import lxml.etree as le

with open('edu.html','r',encoding='utf-8') as f: #打开edu.html文档
    html=f.read() #读取上述文档 并赋值给html
    html_x=le.HTML(html) #将字符串转化为Xpath对象
    div_x_s=html_x.xpath('//div[@class="card_list rec_wrap"]')
    data_s=[] #空列表
    for div_x in div_x_s:
        category1=div_x.xpath('.//em[@class="card_title"]/text()') #第一级分类
        category2_s=div_x.xpath('.//p[@class="headP"]/text()') #第二级分类
        data_s.append(
            dict(
                category1=category1,
                category2_s=category2_s
            )
        ) #制作成字典形式 放入列表
for data in data_s:
    print(data.get('category1')[0])
    for category2 in data.get('category2_s'):
        print('   ',category2)